FROM node:16-alpine AS build

WORKDIR /app/frontend

# 复制项目文件到工作目录
COPY .npmrc ./
COPY package.json ./

# 安装依赖
RUN npm install

# 复制项目源文件到工作目录
COPY . ./

# 构建项目
RUN npm run build

FROM nginx:latest

# 复制构建后的文件
COPY nginx.conf /etc/nginx/conf.d/
COPY --from=build /app/frontend/dist /usr/share/nginx/html

# 暴露 Nginx 端口
EXPOSE 80

# 启动 Nginx
CMD ["nginx", "-g", "daemon off;"]
